package actionHandlers;

/*
 * Action Handler for Redo functionality:
 * pops item off stack and puts it back
 * on the shapes array list and repaints.
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Stack;

import cuShapes.ShapeList;
import palette.CanvasManager;
import palette.CanvasWindow;

/*
 * @author: Daniel Miller
 */

public class RedoHandler implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		//List<PQShape> List = ((CanvasWindow)CanvasManager.getInst().getSelectedFrame()).getCanvas().getShapeList();
		CanvasWindow currWin = ((CanvasWindow)CanvasManager.getInst().getSelectedFrame());
		Stack<ShapeList> redoStack = currWin.getRedoStack();
		if(!redoStack.isEmpty())
		{
			ShapeList item = redoStack.pop();
			try{
				currWin.getUndoStack().push(currWin.getShapeList().getDeepCopy());
			}
			catch(Exception ex){
				System.out.println("Error in deep copy");
			}
			
			currWin.setShapeList(item);
			currWin.getShapeList().setCurrentShape(null);
			item.update();
		}
	}
}
